package com.app.Activity;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
//--

import com.app.Adapter.RuleAdapter;
import com.app.Controller.NetworkController;
import com.app.Controller.ReadWriteFileController;
import com.app.PhanQuyen.Quyen;
import com.app.RowDTO.RuleRowDTO;

public class frmQuyenCuaToi extends Activity {
	ListView lvDanhSachRule;
	Button btnChapNhan;
	Button btnHuyBo;
	TextView txtCount;
	public ArrayList<RuleRowDTO> data;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_danh_sach_rule);
		lvDanhSachRule = (ListView) findViewById(R.id.lvDanhSachRule);
		btnChapNhan = (Button) findViewById(R.id.btnChapNhan);
		btnHuyBo = (Button) findViewById(R.id.btnHuyBo);
		txtCount = (TextView) findViewById(R.id.txtCountSelected);
		fillListView();
	}

	public void fillListView() {
		try {
			ArrayList<Quyen> ruleList = NetworkController._peer.getAccount().getRule();
			data = new ArrayList<RuleRowDTO>();
			for (Quyen rule : ruleList) {

				RuleRowDTO row = new RuleRowDTO();
				row.rule = rule;
				row.check = false;
				data.add(row);
			}
			RuleAdapter adapter = new RuleAdapter(this, data);
			lvDanhSachRule.setAdapter(adapter);
		} catch (Exception e) {
		}

	}

	public void countSelectItem() {
		int n = data.size();
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (data.get(i).check)
				count++;
		}
		txtCount.setText(count + "");
	}
}
